/**
 * 入库单相关路由
 */
const express = require('express');
const router = express.Router();
const stockInController = require('../controllers/stockInController');
const { authenticate, authorize } = require('../middlewares/auth');
const { authMiddleware } = require('../middleware/auth');

// 获取入库单列表
router.get('/', authenticate, stockInController.getStockInOrders);

// 获取入库单详情
router.get('/:id', authenticate, stockInController.getStockInOrderById);

// 创建入库单
router.post('/', authenticate, authorize(['admin', 'manager']), stockInController.createStockInOrder);

// 更新入库单
router.put('/:id', authenticate, authorize(['admin', 'manager']), stockInController.updateStockInOrder);

// 删除入库单
router.delete('/:id', authenticate, authorize(['admin']), stockInController.deleteStockInOrder);

// 确认入库单
router.post('/:id/confirm', authenticate, authorize(['admin', 'manager']), stockInController.confirmStockInOrder);

// 取消入库单
router.post('/:id/cancel', authenticate, authorize(['admin', 'manager']), stockInController.cancelStockInOrder);

// 入库单明细相关路由
router.post('/:id/items', authenticate, authorize(['admin', 'manager']), stockInController.addStockInItem);
router.put('/:id/items/:itemId', authenticate, authorize(['admin', 'manager']), stockInController.updateStockInItem);
router.delete('/:id/items/:itemId', authenticate, authorize(['admin', 'manager']), stockInController.deleteStockInItem);

router.use(authMiddleware);

module.exports = router; 